package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.DaoEcologyPoints;
import com.sc.nft.entity.DaoEcologyPointsWallet;
import com.sc.nft.entity.vo.AdminDaoEcologyPointsVO;
import com.sc.nft.entity.vo.AdminDaoEcologyPointsWalletVO;
import com.sc.nft.entity.vo.AdminManagementRecordPageVO;
import com.sc.nft.mapper.DaoEcologyPointsWalletMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @Author：LiGen
 * @Package：com.sc.nft.dao
 * @Project：sc_metago
 * @name：DaoEcologyPointsWalletDao
 * @Date：2024/11/26 11:08
 * @Filename：DaoEcologyPointsWalletDao
 */
@Slf4j
@Repository
public class DaoEcologyPointsWalletDao extends ServiceImpl<DaoEcologyPointsWalletMapper, DaoEcologyPointsWallet> {


    public DaoEcologyPointsWallet getByDaoId(Long daoId) {
        LambdaQueryWrapper<DaoEcologyPointsWallet> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DaoEcologyPointsWallet::getDaoId, daoId);
        return getOne(wrapper);
    }


//    public boolean addAmount(Long daoId, BigDecimal amount) {
//        LambdaUpdateWrapper<DaoEcologyPointsWallet> wrapper = new LambdaUpdateWrapper<>();
//        wrapper.eq(DaoEcologyPointsWallet::getDaoId, daoId);
//        wrapper.setSql("sum_income_amount = sum_income_amount+" + amount + " , amount = amount + " + amount);
//        return update(wrapper);
//    }



//    public boolean subAllAmount(Long daoId, BigDecimal amount) {
//        LambdaUpdateWrapper<DaoEcologyPointsWallet> wrapper = new LambdaUpdateWrapper<>();
//        wrapper.eq(DaoEcologyPointsWallet::getDaoId, daoId);
//        wrapper.setSql("amount = amount - " + amount);
//        return update(wrapper);
//    }



    public Page<AdminDaoEcologyPointsWalletVO> getPage(String daoName, Page page) {
        return baseMapper.getPage(page, daoName);
    }


    public DaoEcologyPointsWallet getByDaoIdAndPointsId(Long daoId, Long pointsId) {
        LambdaQueryWrapper<DaoEcologyPointsWallet> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(DaoEcologyPointsWallet::getDaoId,daoId);
        lambdaQueryWrapper.eq(DaoEcologyPointsWallet::getPointsId,pointsId);
        lambdaQueryWrapper.last("order by id desc limit 1");
        return getOne(lambdaQueryWrapper);
    }

    public Boolean addAmount(Long id, BigDecimal amount, BigDecimal oldAmount) {
        return baseMapper.addAmount(id, amount, oldAmount);
    }

    public Boolean subAmount(Long id, BigDecimal amount, BigDecimal oldAmount) {
        return baseMapper.subAmount(id, amount, oldAmount);
    }
}
